﻿using DelonixRegia.Classes;
using DelonixRegia.Classes.RoomRecords;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DelonixRegia
{
    public partial class ModifyRoomDetail : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnRoomSearch_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(tbxHotelRoomNumber.Text))
            {
                Classes.Room r = RoomRecordsDBManager.GetRoomDetail(Convert.ToInt32(tbxHotelRoomNumber.Text));

                if (r.roomNo != 0)
                {
                    lblHotelRoomNumber.Text = r.roomNo.ToString();
                    lblHotelRoomLevel.Text = r.roomLevel.ToString();

                    string roomType = r.roomType.ToString();
                    if (roomType == "1")
                    {
                        roomType = "Single";
                    }
                    else if (roomType == "2")
                    {
                        roomType = "Queen";
                    }
                    else if (roomType == "3")
                    {
                        roomType = "Premium";
                    }
                    else
                    {
                        roomType = "Presidential Suite";
                    }
                    lblHotelRoomType.Text = roomType;

                    string balcony = r.balcony.ToString();
                    if (balcony == "False")
                    {
                        balcony = "No";
                    }
                    else
                    {
                        balcony = "Yes";
                    }
                    lblHotelRoomBalcony.Text = balcony;

                    string smoking = r.smoking.ToString();
                    if (smoking == "False")
                    {
                        smoking = "No Smoking";
                    }
                    else
                    {
                        smoking = "Smoking";
                    }
                    lblHotelRoomSmoking.Text = smoking;

                    pnlFirstStep.Visible = false;
                    pnlSecondStep.Visible = true;
                    Page.ClientScript.RegisterStartupScript(GetType(), "transitionToSecondStep", "transitionToSecondStep();", true);
                }
                else
                {
                    ClientScriptMgr.showErrorBox("The Room Number you entered is incorrect or does not exist!");
                }
            }
            else
            {
                ClientScriptMgr.showErrorBox("Please enter the following Room Number!");
            }
        }

        protected void btnEditDetails_Click(object sender, EventArgs e)
        {
            Classes.Room r = RoomRecordsDBManager.GetRoomDetail(Convert.ToInt32(tbxHotelRoomNumber.Text));

            tbxHotelRoomNo.Text = r.roomNo.ToString();
            ddlGuestRoomType.SelectedValue = r.roomType.ToString();
            ddlHotelRoomLevel.SelectedValue = r.roomLevel.ToString();

            if (r.balcony.ToString().Equals("False"))
            {
                rblRoomBalcony.SelectedIndex = 1;
            }
            else
            {
                rblRoomBalcony.SelectedIndex = 0;
            }

            if (r.smoking.ToString().Equals("True"))
            {
                rblRoomSmoke.SelectedIndex = 0;
            }
            else
            {
                rblRoomSmoke.SelectedIndex = 1;
            }



            pnlSecondStep.Visible = false;
            pnlThirdStep.Visible = true;
            Page.ClientScript.RegisterStartupScript(GetType(), "transitionToThirdStep", "transitionToThirdStep();", true);
        }

        protected void btnSaveDetails_Click(object sender, EventArgs e)
        {
            Classes.Room r = new Classes.Room();
            r.roomNo = Convert.ToInt32(tbxHotelRoomNo.Text);
            r.roomType = Convert.ToInt32(ddlGuestRoomType.SelectedValue);
            r.roomLevel = Convert.ToInt32(ddlHotelRoomLevel.SelectedValue);

            bool balcony = false;
            if (rblRoomBalcony.SelectedIndex == 0)
            {
                balcony = true;
            }
            else
            {
                balcony = false;
            }
            r.balcony = balcony;

            bool smoking = false;
            if (rblRoomSmoke.SelectedIndex == 0)
            {
                smoking = true;
            }
            else
            {
                smoking = false;
            }
            r.smoking = smoking;

            if (RoomRecordsDBManager.UpdateRoomDetail(r) == true)
            {
                pnlThirdStep.Visible = false;
                pnlFourthStep.Visible = true;
                Page.ClientScript.RegisterStartupScript(GetType(), "transitionToThirdStep", "transitionToThirdStep();", true);
            }
            else
            {
                ClientScriptMgr.Execute("$('#searchErrorBox').html('<strong>Error:</strong> Failed to update Room details');$('#searchErrorBox').hide().show();");
            }
        }

        protected void btnGoBackPanel2_Click(object sender, EventArgs e)
        {
            tbxHotelRoomNumber.Text = "";
            pnlSecondStep.Visible = false;
            pnlFirstStep.Visible = true;
            Page.ClientScript.RegisterStartupScript(GetType(), "transitionToFirstStep", "transitionToFirstStep();", true);
        }

        protected void btnGoBackPanel3_Click(object sender, EventArgs e)
        {
            tbxHotelRoomNumber.Text = "";
            pnlThirdStep.Visible = false;
            pnlFirstStep.Visible = true;
            Page.ClientScript.RegisterStartupScript(GetType(), "transitionToFirstStep", "transitionToFirstStep();", true);
        }

        protected void btnGoBackPanel4_Click(object sender, EventArgs e)
        {
            tbxHotelRoomNumber.Text = "";
            pnlFourthStep.Visible = false;
            pnlFirstStep.Visible = true;
            Page.ClientScript.RegisterStartupScript(GetType(), "transitionToFirstStep", "transitionToFirstStep();", true);
        }
    }
}